<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SunCMS 后台管理系统</title>
<link href="./images/system/style.css" rel="stylesheet" type="text/css">
<script src="./include/javascript/jquery.js" type="text/javascript"></script>
<script src="./include/javascript/main.js" type="text/javascript"></script>
<script type="text/javascript">
	var SCRIPT='<?php echo SCRIPT_NAME?>';
	var SITE_URL='<?php echo SITE_URL?>';
</script>

<script type="text/javascript" src="./admin/javascript/.js"></script>
<script type="text/javascript">
var docMag = {
	_allowNewMore: true,
	_allowNewDocument: false,
	preview: function(id)
	{
		var ids = global.getChecked();
		if(ids=='')parent.dialog.alert('请选择要预览的文档！');
		else if(ids.length>1)parent.dialog.alert('参数错误，请重新操作！');
		else{parent.dialog.iframe(1,'文档预览','?m=dialog&a=preview&id='+ids[0],2,0,800,450);}
	},
	newDocument: function()
	{
		if(this._allowNewDocument==false)return false;
		var catid = $("#catid").val();
		var model = $("#model").val();
		window.location=SITE_URL+SCRIPT+'?m=document&a=new&do=index&model='+model+'&catid='+catid;
	},
	newMore: function()
	{
		if(this.allowNewMore==false)return false;
		var ids = global.getChecked();
		if(ids=='')parent.dialog.alert('请选择要续发的文档！');
		else if(ids.length>1)parent.dialog.alert('参数错误，请重新操作！');
		else{parent.dialog.iframe(1,'文档预览','?m=document&a=new&do=newmore&id='+ids[0],2,0,800,450);}
	},
	editSelect: function(id)
	{
		var ids;
		var editId;
		if(typeof id == "undefined")
		{
			var ids = global.getChecked();
			if(ids=='')
			{
				parent.dialog.alert('请选择要编辑的文档！');
				return false;
			}
			else if(ids.length>1)
			{
				parent.dialog.alert('参数错误，请重新操作！');
				return false;
			}
			editId = ids[0];
		}
		else
		{
			editId = id;
		}
		$.ajax({
			url: SITE_URL+SCRIPT+"?m=article&a=edit&do=editcheck&id="+editId,
			error: function (xmlHttpRequest, error) {
				parent.dialog.alert('从服务器获取数据异常！');
			},
			success: function(rs)
			{
				if(rs)
				{
					parent.dialog.iframe(1,'编辑模式选择','?m=article&a=edit&do=editarticle&id='+ids[0],0,1,600,350);
				}
				else{window.location=SITE_URL+SCRIPT+'?m=article&a=edit&do=editarticle&id='+ids[0]+'&page=1';}
			}
		});
	},
	copy: function()
	{
		var ids = global.getChecked();
		if(ids=='')parent.dialog.alert('请选择要复制的文档！');
		else{var strIds = ids.join(',');parent.dialog.iframe(1,'请选择要复制到的分类','?m=article&a=mag&do=newcopy&ids='+strIds,1,1,600,350);}
	},
	move: function()
	{
		var ids = global.getChecked();
		if(ids=='')parent.dialog.alert('请选择要转移的文档！');
		else{var strIds = ids.join(',');parent.dialog.iframe(1,'请选择要转移到的分类','?m=article&a=mag&do=newmove&ids='+strIds,1,1,600,250);}
	},
	delConfirm: function()
	{
		var ids = global.getChecked();
		if(ids=='')parent.dialog.alert('请选择要删除的文档！');
		else{var strIds = ids.join(',');parent.dialog.query('此操作不可恢复，是否确定删除？',"app.documentDel('"+strIds+"')");}
	},
	getCategoryMenu: function()
	{
		/** todo: 获取栏目树 **/
		var model = $("#model").val();
		$.ajax({
			url: SITE_URL+SCRIPT+"?m=document&a=mag&do=getcategory",
			data:{'model':model},
			error: function (xmlHttpRequest, error) {
				parent.dialog.alert('AJAX数据获取异常！');
			},
			success: function(rs)
			{
				$("#cat_menu").empty();
				var html = '';
				for(i in rs)
				{
					var treeStyle=rs[i].level>2?'none':'block';
					var active = i==0?' tree_active':'';
					html+='<div class="tree_item'+active;
					html+='" style="display:'+treeStyle+'" id="cat_'+rs[i].id+'" pid="'+rs[i].pid+'" onclick="docMag.treeClick('+rs[i].id+','+rs[i].onepage+')" ';
					html+='>'+rs[i].img+rs[i].name+'</div>';
				}
				flag = model=='article'?true:false;
				flag?$("#new_more").removeClass('sbt_disabled'):$("#new_more").addClass('sbt_disabled');
				this._allowNewMore = flag;
				$("#new_document").addClass('sbt_disabled');
				this._allowNewDocument = false;
				$("#catid").val(0);
				$("#cat_menu").html(html);
				$("#cat_menu #cat_0").addClass("tree_active");
				docMag.getDocumentList();
			}
		});
	},
	getDocumentList: function(page)
	{
		/** todo: 获取文档列表 **/
		$("#loading_doc").show();
		page = (typeof page == 'undefined')?1:page;
		var currCatId =  $("#catid").val();
		var status = $("#status").val();
		var stime = $("#stime").val();
		var etime = $("#etime").val();
		var keywords = $("#keywords").val();
		var model = $("#model").val();
		$.ajax({
			url: SITE_URL+SCRIPT+"?m=document&a=mag&do=getlist",
			data: {'catid':currCatId,'page':page,'status':status,'stime':stime,'etime':etime,'keywords':keywords,'model':model},
			error: function (xmlHttpRequest, error) {
				$("#loading_doc").hide();
				parent.dialog.alert('AJAX数据获取异常！');
			},
			success: function(rs)
			{
				var html = '';
				var documentArr = rs.documents;
				var documentNo = rs.documents_no;
				var pageNo = rs.page_no;
				for(i in documentArr)
				{
					html+='<tr class="doc_item" onclick="global.lineClick('+documentArr[i].id+');" id="tr_'+documentArr[i].id+'" ondblclick="docMag.editSelect('+documentArr[i].id+');"><td>'+documentArr[i].id+'</td><td><input type="checkbox" class="checkbox" onclick="global.lineClick('+documentArr[i].id+');" value='+documentArr[i].id+'></td><td>'+documentArr[i].title+'</td><td>'+documentArr[i].username+'</td><td>'+documentArr[i].recommend+'</td><td>'+documentArr[i].status+'</td><td>'+documentArr[i].post_time+'</td></tr>'
				}
				var pageInfo = '共 '+documentNo+' 条记录，每页 15 条，当前第 '+page+' / '+pageNo+' 页';
				var pagination = '';
				pagination += (page!=1)?'<a href="javascript:void(0);" onclick="docMag.getDocumentList(1);">第一页</a>| ':'第一页| ';
				pagination += (page>1)?'<a href="javascript:void(0);" onclick="docMag.getDocumentList('+(page-1)+');">上一页</a>| ':'上一页| ';
				pagination += (page<pageNo)?'<a href="javascript:void(0);" onclick="docMag.getDocumentList('+(page+1)+');">下一页</a>| ':'下一页| ';
				pagination += (page!=pageNo)?'<a href="javascript:void(0);" onclick="docMag.getDocumentList('+pageNo+');">最末页</a> ':'最末页 ';
				pagination += ' 转到第 <input type="text" onkeyup="value=value.replace(/\D/g,\'\')" style="width: 40px;" class="sinput" id="gopage"/> 页 <a class="slbutton" href="javascript:void(1);" onclick="docMag.gopage('+page+','+pageNo+');"><input type="button" class="srbutton" value="跳转"/></a>';
				if(($("#onepage").val() == 1) && (documentArr.length == 1))
				{
					$("#new_document").addClass('sbt_disabled');
					docMag.allowNewDocument = false;
					$("#new_more").addClass('sbt_disabled');
					docMag.allowNewMore = false;
				}
				$(".doc_item").remove();
				$("#doc_list").append(html);
				$("#page_info").text(pageInfo);
				$("#pagination").html(pagination);
				window.setTimeout('$("#loading_doc").hide();',300);
			}
		});
	},
	treeClick: function(catid,onepage)
	{
		var currCatId =  $("#catid").val();
		if(currCatId==catid)return false;
		$("#cat_menu .tree_item").removeClass("tree_active");
		$("#cat_menu #cat_"+catid).addClass("tree_active");
		var flag = catid==0?true:false;
		flag?$("#new_document").addClass('sbt_disabled'):$("#new_document").removeClass('sbt_disabled');
		this._allowNewDocument = flag;
		$("#catid").val(catid);
		$("#onepage").val(onepage);
		this.getDocumentList();
	}
}
</script>
</head>
<body>
<input type='hidden' id='catid' value='0'>
<input type='hidden' id='onepage' value='0'>
<table cellspacing="0" cellpadding="0" border="0" width="100%" height='100%'>
	<tbody>
	<tr>
		<td style='width:200px;' valign='top'>
<div class="main" style='margin-right:0px;'>
<div class='main_left'>
<div class='main_right' style='padding:7px;'>
	<div style='margin:0 0 5px 5px;'>
		文档模型：<select id='model' onchange='docMag.getCategoryMenu();' style='height:18px; width:75px;'>
			<option value='article'>&nbsp;&nbsp;文章
			<option value='picture'>&nbsp;&nbsp;图片
			<option value='video'>&nbsp;&nbsp;视频
			<option value='download'>&nbsp;&nbsp;下载
			<option value='product'>&nbsp;&nbsp;产品
		</select>
	</div>
	<div id='cat_menu'>
	<?php foreach( $tree as $v ){?>
		<div class="tree_item <?php if($v['id']==0)echo 'tree_active'; ?>" id="cat_<?php echo $v['id']; ?>" pid="<?php echo $v['pid'].'" '; if($v['level']>2){ ?> style='display:none;' <?php } ?>onclick="docMag.treeClick(<?php echo $v['id'].",".$v['onepage']; ?>);"<?php echo '>'.$v['img'].$v['name']; ?></div>
	<?php }?>
	</div>
</div><!-- /main_right -->
</div><!-- /main_left -->
</div><!-- /main -->
		</td>
		<td valign='top'>
<div class="main">
<div class='main_left'>
<div class='main_right'>
	<table cellspacing="0" cellpadding="0" border="0" width="100%">
	<tbody>
	<tr>
		<td width="65%" style="padding: 6px 0;">
			<div class='f_left' id='tb_menu1'>
				<a class='sbutton sbt_disabled' onclick="docMag.newDocument();" href="javascript:void(0);" id='new_document'><img height="20" width="20" src="./images/system/icon/40.gif"/><b>新建</b></a>
				<a class='sbutton' onclick="docMag.newMore();" href="javascript:void(0);" id='new_more'><img height="20" width="20" src="./images/system/icon/36.gif"/><b>续发</b></a>
				<a class='sbutton' onclick="docMag.editSelect();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/40.gif"/><b>编辑</b></a>
				<a class='sbutton' onclick="docMag.preview();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/41.gif"/><b>预览</b></a>
				<a class='sbutton' onclick="docMag.copy();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/42.gif"/><b>复制</b></a>
				<a class='sbutton' onclick="docMag.move();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/43.gif"/><b>转移</b></a>
				<a class='sbutton' onclick="docMag.delConfirm();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/44.gif"/><b>删除</b></a>
			</div>
		</td>
	</tr>
	<tr>
		<td style="padding: 2px 0;">
			<div class='f_left' >列出: 
				<select style='width: 120px;' id='status' onchange="docMag.getDocumentList()">
					<option value='all'>&nbsp;&nbsp;所有文档
					<option value='my'>&nbsp;&nbsp;我创建的文档
					<option value='0'>&nbsp;&nbsp;流转中的文档
					<option value='2'>&nbsp;&nbsp;待发布的文档
					<option value='1'>&nbsp;&nbsp;已发布的文档
					<option value='3'>&nbsp;&nbsp;已下线的文档
				</select>
			</div> 
			<div class='f_left' style="padding-left:10px;">
				从 <input type="text" style="width: 80px;" id="stime" class="sinput"/><img align="absmiddle" vspace="1" src="./images/system/Calendar.gif"/> 
				至 <input type="text" style="width: 80px;" id="etime" class="sinput"/><img align="absmiddle" vspace="1" src="./images/system/Calendar.gif"/>
			</div>
			<div class='f_left' style="padding-left:10px;">
				关键词: <input type="text" id="keywords" class="sinput"/> <a class="slbutton" href="javascript:void(1);" onclick='docMag.getDocumentList();'><input type="button" class="srbutton" value="查询" /></a>
			</div>
		</td>
	</tr>
	<tr>
		<td style="padding: 2px 0;">
		<table cellspacing="0" cellpadding="2" width="100%" class="stable">
			<tbody id='doc_list'>
			<tr class="tableth">
				<td width="5%">ID</td>
				<td width="4%"><input type="checkbox" id="checkbox" onclick="checkall();"></td>
				<td width="50%">标题</td>
				<td width="11%">创建者</td>
				<td width="5%">推荐</td>
				<td width="6%">状态</td>
				<td width="14%">发布时间</td>
			</tr>
			<?php foreach( $articles as $k => $v ){?>
			<tr class="doc_item" onclick='global.lineClick(<?php echo $v['id']; ?>);' id='tr_<?php echo $v['id']; ?>' ondblclick='docMag.editSelect(<?php echo $v['id']; ?>);'>
				<td><?php echo $v['id']; ?></td>
				<td><input type="checkbox" class="checkbox" value='<?php echo $v['id']; ?>' onclick='global.lineClick(<?php echo $v['id']; ?>);'></td>
				<td><?php echo $v['title']; ?></td>
				<td><?php echo $v['username']; ?></td>
				<td><?php echo $v['recommend']; ?></td>
				<td><?php echo $v['status']; ?></td>
				<td><?php echo $v['post_time']; ?></td>
			</tr>
			<?php } ?>
			</tbody>
			</table>
			<table cellspacing="0" cellpadding="2" width="100%" class='ptable'>
				<tbody>
					<tr>
						<td align="left" valign='center' id='page_table'>
							<div class="f_left" id='page_info'>共 <?php echo $document_no; ?> 条记录，每页 15 条，当前第 <?php echo $page; ?> / <?php echo $page_no; ?> 页</div>
							<div class="f_right" id='pagination'>
								<?php if($first){?><a href="javascript:void(0);" onclick="docMag.getDocumentList(<?php echo $first; ?>);">第一页</a><?php }else{?>第一页<?php }?>| 
								<?php if($prev){?><a href="javascript:void(0);" onclick="docMag.getDocumentList(<?php echo $prev; ?>);">上一页</a><?php }else{?>上一页<?php }?>| 
								<?php if($next){?><a href="javascript:void(0);" onclick="docMag.getDocumentList(<?php echo $next; ?>);">下一页</a><?php }else{?>下一页<?php }?>| 
								<?php if($last){?><a href="javascript:void(0);" onclick="docMag.getDocumentList(<?php echo $last; ?>);">最末页</a><?php }else{?>最末页<?php }?>
								转到第 <input type="text" onkeyup="value=value.replace(/\D/g,'')" style="width: 40px;" class="sinput" id="gopage"/> 页  
								<a class="slbutton" href="javascript:void(1);" onclick="gopage(<?php echo $page; ?>,<?php echo $page_no; ?>);"><input type="button" class="srbutton" value="跳转"/></a>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</td>
	</tr>
	</tbody>
	</table>
</div><!-- /main_right -->
</div><!-- /main_left -->
</div><!-- /main -->
		</td>
	</tr>
	</tbody>
</table>
<div id="loading_doc" style="padding-top: 5px; background-color: #FFFFCC; position: absolute; z-index: 801; height: 20px; width: 120px; top: 70px;*top:73px; left: 218px;display:none;">
	<img src="./images/system/icon/67.gif"/><font style='color:#008000;'> 正在加载......　</font>
</div>
</body>
</html>